package cn.rubintry.bug.hunting.common.http.viewmodel

import androidx.activity.ComponentActivity
import androidx.lifecycle.MutableLiveData
import cn.rubintry.bug.hunting.common.http.api.WebApi
import cn.rubintry.bug.hunting.pojo.ArticleModel
import cn.rubintry.bug.hunting.pojo.BaseModel
import cn.rubintry.bug.hunting.pojo.HomeBackgroundModel
import cn.rubintry.bug.hunting.pojo.TagDataModel
import cn.rubintry.bug.lib.network.http.NetApiManager
import cn.rubintry.bug.lib.network.http.viewmodel.BaseViewModel

class DiscoverViewModel() : BaseViewModel() {

    val tagData : MutableLiveData<BaseModel<List<TagDataModel>>> = MutableLiveData()
    val tagArticleData : MutableLiveData<BaseModel<List<ArticleModel>>> = MutableLiveData()
    val bannerData : MutableLiveData<BaseModel<List<HomeBackgroundModel>>> = MutableLiveData()

    fun getTags(){
        request(
            NetApiManager.getInstance().getApi(WebApi::class.java),
            WebApi::getTags,
            false,
            {data ->
                data?.let {
                    tagData.value = it
                }
            })
    }

    fun getArticleByTag(tagId: String) {
        request(
            NetApiManager.getInstance().getApi(WebApi::class.java),
            WebApi::getSourceFromTag,
            false,
            {data ->
                data?.let {
                    tagArticleData.value = it
                }
            }, tagId)
    }


    fun getBannerImage(){
        request(
            NetApiManager.getInstance().getApi(WebApi::class.java),
            WebApi::getMobileBannerImages,
            false,
            { data ->
                data?.let {
                    bannerData.value = it
                }
            }
        )
    }


}